<template>
  <div class="pd-le-ri">
    <div class="crumbs">
      <el-breadcrumb separator="/">
        <el-breadcrumb-item>
          <el-icon :size="11">
            <user-filled />
          </el-icon> 用户管理
        </el-breadcrumb-item>
      </el-breadcrumb>
    </div>
    <div class="container">
      <div style="min-width: 800px; display: flex">
        <el-select v-model="regionId" class="m-2" placeholder="选择区域">
          <el-option v-for="item in typeList" :key="item.id" :label="item.campusName" :value="item.id" />
        </el-select>
        <div style="margin: 0 20px">
          <el-button type="primary" @click="clickBtn">搜索</el-button>
        </div>
      </div>
      <div style="margin: 20px 0 30px">
        <el-table :data="tableData.arr" border style="width: 100%" :stripe="true">
          <el-table-column prop="nikeName" label="用户名" width="200" />
          <el-table-column align="center" label="头像" width="200">
            <template v-slot="scope">
              <el-image style="width: 50px; height: 50px" fit="cover" :src="scope.row.headImg"
                :preview-src-list="[scope.row.headImg]"></el-image>
            </template>
          </el-table-column>
          <el-table-column prop="id" label="用户ID" width="250"></el-table-column>
          <el-table-column prop="userId" label="userID" width="250"></el-table-column>
          <el-table-column prop="phone" label="电话号码" width="200"></el-table-column>
          <el-table-column align="center" label="收款码" width="200">
            <template v-slot="scope">
              <el-image style="width: 50px; height: 50px" fit="cover" :src="scope.row.collectionCode"
                :preview-src-list="[scope.row.collectionCode]"></el-image>
            </template>
          </el-table-column>
          <el-table-column label="操作" align="center">
            <template v-slot="scope">
              <el-button size="small" v-if="scope.row.status == 0" @click="closeAdmin(scope.row.userId)" type="danger">禁用</el-button>
              <el-button type="success" size="small" v-if="scope.row.status == 1" @click="openAdmin(scope.row.userId)">
                开启</el-button>
            </template>
          </el-table-column>
        </el-table>
      </div>
      <div style="margin-bottom: 10px">
        <div class="demo-pagination-block">
          <el-pagination :page-size="10" layout="total, prev, pager, next, jumper" :total="total"
            @current-change="handleCurrentChange">
          </el-pagination>
        </div>
      </div>
    </div>
  </div>
</template>

<script lang="ts">
import { defineComponent, ref, reactive, onMounted } from "vue";
import { getUesrList, editUser } from '../../http/user/user'
import { getType } from '../../http/order/order'
import { UserFilled } from "@element-plus/icons";

export default defineComponent({
  components: {
    UserFilled,
  },
  setup() {

    let tableData = reactive({
      arr: [],
    });
    let total = ref();
    let page = ref(1);
    let mangerId = ref("");
    let userId = ref("")
    let roleType = ref("")
    let campusName = ref("")
    const dialogVisible = ref(false);
    let typeList: any = ref([]);
    const regionId = ref('');

    onMounted(async() => {
      getList();
      const res: any = await getType();
      typeList.value = res.data;
    });

    const getList = async () => {
      const data = {
        pageNum: page.value,
        pageSize: 10,
        regionId:regionId.value
      };
      const res: any = await getUesrList(data);
      tableData.arr = res.data.records;
      total.value = res.data.total;
    };

    const handleCurrentChange = (e: number) => {
      page.value = e;
      getList();
    };

    const clickBtn = () => {
      getList();
    };

    const openAdmin = async (e: any) => {
      let changge = {
        staffId: e,
        status: 1,
      };
      const res: any = await editUser();
      getList();
    };

    const closeAdmin = async (e: any) => {
      let changge = {
        staffId: e,
        status: 0,
      };
      const res: any = await editUser();
      getList();
    };

    return {
      mangerId,
      tableData,
      total,
      userId,
      roleType,
      campusName,
      dialogVisible,
      typeList,
      regionId,
      handleCurrentChange,
      clickBtn,
      openAdmin,
      closeAdmin,
    };
  },
});
</script>

<style scoped>

</style>
